<?php
class CmsCommentModel extends Model
{
    protected static $instance;

    public static function GetInstance()
    {
        return self::$instance ? self::$instance : self::$instance = new CmsCommentModel();
    }

    public function GetByPostId($post_id)
    {
        return $this->FindBy('post_id', $post_id);
    }

    protected function ValidateBeforeInsert(&$item)
    {
        parent::ValidateBeforeInsert($item);

        if ($this->IsEmpty('name', $item))
            throw new Exception('Name is required');

        if ($this->IsEmpty('email', $item))
            throw new Exception('Email is required');

        if (!String::IsValidEmail($item['email']))
            throw new Exception('Email is not valid');

        if ($this->IsEmpty('content', $item))
            throw new Exception('Comment is empty');
    }
}
?>
